{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Create Networks - Advanced"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This tutorial shows how to create a more complex pandapower network step by step. The network includes every element which is availiable in the pandapower framework.\n",
    "\n",
    "The final network looks like this:\n",
    "\n",
    "<img src=\"pics/example_network.png\" width=\"50%\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The structural information about this network are stored in csv tables in the example_advanced folder.\n",
    "\n",
    "For a better overview the creation of the individual components is divided in three steps. Each step handles one of the three voltage levels: high, medium and low voltage. We star by initializing an empty pandapower network:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "#import the pandapower module\n",
    "import pandapower as pp\n",
    "import pandas as pd\n",
    "\n",
    "#create an empty network \n",
    "net = pp.create_empty_network()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## High voltage level"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Buses\n",
    "\n",
    "<img src=\"pics/example_network_buses_hv_detail.png\" width=\"50%\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "There are two 380 kV and five 110 kV busbars (type=\"b\"). The 380/110 kV substation is modeled in detail with all nodes and switches, which is why we need additional nodes (type=\"b\") to connect the switches."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>vn_kv</th>\n",
       "      <th>type</th>\n",
       "      <th>zone</th>\n",
       "      <th>in_service</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Double Busbar 1</td>\n",
       "      <td>380.0</td>\n",
       "      <td>b</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Double Busbar 2</td>\n",
       "      <td>380.0</td>\n",
       "      <td>b</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Bus DB T0</td>\n",
       "      <td>380.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Bus DB T1</td>\n",
       "      <td>380.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Bus DB T2</td>\n",
       "      <td>380.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>Bus DB T3</td>\n",
       "      <td>380.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Bus DB T4</td>\n",
       "      <td>380.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>Bus DB T5</td>\n",
       "      <td>380.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>Bus DB T6</td>\n",
       "      <td>380.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>Bus DB T7</td>\n",
       "      <td>380.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>Bus DB T8</td>\n",
       "      <td>380.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>Bus DB T9</td>\n",
       "      <td>380.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>Bus DB 1</td>\n",
       "      <td>380.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>Bus DB 2</td>\n",
       "      <td>380.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>Bus DB 3</td>\n",
       "      <td>380.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>Bus DB 4</td>\n",
       "      <td>380.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>Single Busbar</td>\n",
       "      <td>110.0</td>\n",
       "      <td>b</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>Bus SB 1</td>\n",
       "      <td>110.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>Bus SB 2</td>\n",
       "      <td>110.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>Bus SB 3</td>\n",
       "      <td>110.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>Bus SB 4</td>\n",
       "      <td>110.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>Bus SB 5</td>\n",
       "      <td>110.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>Bus SB T1.1</td>\n",
       "      <td>110.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>Bus SB T1.2</td>\n",
       "      <td>110.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>Bus SB T2.1</td>\n",
       "      <td>110.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>Bus SB T2.2</td>\n",
       "      <td>110.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>Bus SB T3.1</td>\n",
       "      <td>110.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>Bus SB T3.2</td>\n",
       "      <td>110.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>Bus SB T4.1</td>\n",
       "      <td>110.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>Bus SB T4.2</td>\n",
       "      <td>110.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>Bus SB T5.1</td>\n",
       "      <td>110.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>Bus SB T5.2</td>\n",
       "      <td>110.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>Bus HV1</td>\n",
       "      <td>110.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>Bus HV2</td>\n",
       "      <td>110.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>Bus HV3</td>\n",
       "      <td>110.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>Bus HV4</td>\n",
       "      <td>110.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               name  vn_kv type  zone  in_service\n",
       "0   Double Busbar 1  380.0    b  None        True\n",
       "1   Double Busbar 2  380.0    b  None        True\n",
       "2         Bus DB T0  380.0    n  None        True\n",
       "3         Bus DB T1  380.0    n  None        True\n",
       "4         Bus DB T2  380.0    n  None        True\n",
       "5         Bus DB T3  380.0    n  None        True\n",
       "6         Bus DB T4  380.0    n  None        True\n",
       "7         Bus DB T5  380.0    n  None        True\n",
       "8         Bus DB T6  380.0    n  None        True\n",
       "9         Bus DB T7  380.0    n  None        True\n",
       "10        Bus DB T8  380.0    n  None        True\n",
       "11        Bus DB T9  380.0    n  None        True\n",
       "12         Bus DB 1  380.0    n  None        True\n",
       "13         Bus DB 2  380.0    n  None        True\n",
       "14         Bus DB 3  380.0    n  None        True\n",
       "15         Bus DB 4  380.0    n  None        True\n",
       "16    Single Busbar  110.0    b  None        True\n",
       "17         Bus SB 1  110.0    n  None        True\n",
       "18         Bus SB 2  110.0    n  None        True\n",
       "19         Bus SB 3  110.0    n  None        True\n",
       "20         Bus SB 4  110.0    n  None        True\n",
       "21         Bus SB 5  110.0    n  None        True\n",
       "22      Bus SB T1.1  110.0    n  None        True\n",
       "23      Bus SB T1.2  110.0    n  None        True\n",
       "24      Bus SB T2.1  110.0    n  None        True\n",
       "25      Bus SB T2.2  110.0    n  None        True\n",
       "26      Bus SB T3.1  110.0    n  None        True\n",
       "27      Bus SB T3.2  110.0    n  None        True\n",
       "28      Bus SB T4.1  110.0    n  None        True\n",
       "29      Bus SB T4.2  110.0    n  None        True\n",
       "30      Bus SB T5.1  110.0    n  None        True\n",
       "31      Bus SB T5.2  110.0    n  None        True\n",
       "32          Bus HV1  110.0    n  None        True\n",
       "33          Bus HV2  110.0    n  None        True\n",
       "34          Bus HV3  110.0    n  None        True\n",
       "35          Bus HV4  110.0    n  None        True"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Double busbar\n",
    "pp.create_bus(net, name='Double Busbar 1', vn_kv=380, type='b')\n",
    "pp.create_bus(net, name='Double Busbar 2', vn_kv=380, type='b')\n",
    "for i in range(10):\n",
    "    pp.create_bus(net, name='Bus DB T%s' % i, vn_kv=380, type='n')\n",
    "for i in range(1, 5):\n",
    "    pp.create_bus(net, name='Bus DB %s' % i, vn_kv=380, type='n')\n",
    "\n",
    "# Single busbar\n",
    "pp.create_bus(net, name='Single Busbar', vn_kv=110, type='b')\n",
    "for i in range(1, 6):\n",
    "    pp.create_bus(net, name='Bus SB %s' % i, vn_kv=110, type='n')\n",
    "for i in range(1, 6):\n",
    "    for j in [1, 2]:\n",
    "        pp.create_bus(net, name='Bus SB T%s.%s' % (i, j), vn_kv=110, type='n')\n",
    "\n",
    "# Remaining buses\n",
    "for i in range(1, 5):\n",
    "    pp.create_bus(net, name='Bus HV%s' % i, vn_kv=110, type='n')\n",
    "\n",
    "# show bustable\n",
    "net.bus"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Lines\n",
    "\n",
    "<img src=\"pics/example_network_lines_hv.png\" width=\"40%\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The information about the 6 HV lines are stored in a csv file that we load from the hard drive:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>line_name</th>\n",
       "      <th>from_bus</th>\n",
       "      <th>to_bus</th>\n",
       "      <th>std_type</th>\n",
       "      <th>length</th>\n",
       "      <th>parallel</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>HV Line1</td>\n",
       "      <td>Bus SB 2</td>\n",
       "      <td>Bus HV1</td>\n",
       "      <td>184-AL1/30-ST1A 110.0</td>\n",
       "      <td>30</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>HV Line2</td>\n",
       "      <td>Bus HV1</td>\n",
       "      <td>Bus HV2</td>\n",
       "      <td>184-AL1/30-ST1A 110.0</td>\n",
       "      <td>20</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>HV Line3</td>\n",
       "      <td>Bus HV2</td>\n",
       "      <td>Bus HV4</td>\n",
       "      <td>184-AL1/30-ST1A 110.0</td>\n",
       "      <td>30</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>HV Line4</td>\n",
       "      <td>Bus HV1</td>\n",
       "      <td>Bus HV4</td>\n",
       "      <td>184-AL1/30-ST1A 110.0</td>\n",
       "      <td>15</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>HV Line5</td>\n",
       "      <td>Bus HV3</td>\n",
       "      <td>Bus HV4</td>\n",
       "      <td>184-AL1/30-ST1A 110.0</td>\n",
       "      <td>25</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>HV Line6</td>\n",
       "      <td>Bus SB 3</td>\n",
       "      <td>Bus HV3</td>\n",
       "      <td>184-AL1/30-ST1A 110.0</td>\n",
       "      <td>30</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  line_name  from_bus   to_bus               std_type  length  parallel\n",
       "0  HV Line1  Bus SB 2  Bus HV1  184-AL1/30-ST1A 110.0      30         1\n",
       "1  HV Line2   Bus HV1  Bus HV2  184-AL1/30-ST1A 110.0      20         1\n",
       "2  HV Line3   Bus HV2  Bus HV4  184-AL1/30-ST1A 110.0      30         1\n",
       "3  HV Line4   Bus HV1  Bus HV4  184-AL1/30-ST1A 110.0      15         1\n",
       "4  HV Line5   Bus HV3  Bus HV4  184-AL1/30-ST1A 110.0      25         1\n",
       "5  HV Line6  Bus SB 3  Bus HV3  184-AL1/30-ST1A 110.0      30         2"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hv_lines = pd.read_csv('example_advanced/hv_lines.csv', sep=';', header=0, decimal=',')\n",
    "hv_lines"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "and use to create all lines:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>std_type</th>\n",
       "      <th>from_bus</th>\n",
       "      <th>to_bus</th>\n",
       "      <th>length_km</th>\n",
       "      <th>r_ohm_per_km</th>\n",
       "      <th>x_ohm_per_km</th>\n",
       "      <th>c_nf_per_km</th>\n",
       "      <th>g_us_per_km</th>\n",
       "      <th>max_i_ka</th>\n",
       "      <th>df</th>\n",
       "      <th>parallel</th>\n",
       "      <th>type</th>\n",
       "      <th>in_service</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>HV Line1</td>\n",
       "      <td>184-AL1/30-ST1A 110.0</td>\n",
       "      <td>18</td>\n",
       "      <td>32</td>\n",
       "      <td>30.0</td>\n",
       "      <td>0.1571</td>\n",
       "      <td>0.4</td>\n",
       "      <td>8.8</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.535</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>ol</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>HV Line2</td>\n",
       "      <td>184-AL1/30-ST1A 110.0</td>\n",
       "      <td>32</td>\n",
       "      <td>33</td>\n",
       "      <td>20.0</td>\n",
       "      <td>0.1571</td>\n",
       "      <td>0.4</td>\n",
       "      <td>8.8</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.535</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>ol</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>HV Line3</td>\n",
       "      <td>184-AL1/30-ST1A 110.0</td>\n",
       "      <td>33</td>\n",
       "      <td>35</td>\n",
       "      <td>30.0</td>\n",
       "      <td>0.1571</td>\n",
       "      <td>0.4</td>\n",
       "      <td>8.8</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.535</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>ol</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>HV Line4</td>\n",
       "      <td>184-AL1/30-ST1A 110.0</td>\n",
       "      <td>32</td>\n",
       "      <td>35</td>\n",
       "      <td>15.0</td>\n",
       "      <td>0.1571</td>\n",
       "      <td>0.4</td>\n",
       "      <td>8.8</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.535</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>ol</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>HV Line5</td>\n",
       "      <td>184-AL1/30-ST1A 110.0</td>\n",
       "      <td>34</td>\n",
       "      <td>35</td>\n",
       "      <td>25.0</td>\n",
       "      <td>0.1571</td>\n",
       "      <td>0.4</td>\n",
       "      <td>8.8</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.535</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>ol</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>HV Line6</td>\n",
       "      <td>184-AL1/30-ST1A 110.0</td>\n",
       "      <td>19</td>\n",
       "      <td>34</td>\n",
       "      <td>30.0</td>\n",
       "      <td>0.1571</td>\n",
       "      <td>0.4</td>\n",
       "      <td>8.8</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.535</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2</td>\n",
       "      <td>ol</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       name               std_type  from_bus  to_bus  length_km  r_ohm_per_km  \\\n",
       "0  HV Line1  184-AL1/30-ST1A 110.0        18      32       30.0        0.1571   \n",
       "1  HV Line2  184-AL1/30-ST1A 110.0        32      33       20.0        0.1571   \n",
       "2  HV Line3  184-AL1/30-ST1A 110.0        33      35       30.0        0.1571   \n",
       "3  HV Line4  184-AL1/30-ST1A 110.0        32      35       15.0        0.1571   \n",
       "4  HV Line5  184-AL1/30-ST1A 110.0        34      35       25.0        0.1571   \n",
       "5  HV Line6  184-AL1/30-ST1A 110.0        19      34       30.0        0.1571   \n",
       "\n",
       "   x_ohm_per_km  c_nf_per_km  g_us_per_km  max_i_ka   df  parallel type  \\\n",
       "0           0.4          8.8          0.0     0.535  1.0         1   ol   \n",
       "1           0.4          8.8          0.0     0.535  1.0         1   ol   \n",
       "2           0.4          8.8          0.0     0.535  1.0         1   ol   \n",
       "3           0.4          8.8          0.0     0.535  1.0         1   ol   \n",
       "4           0.4          8.8          0.0     0.535  1.0         1   ol   \n",
       "5           0.4          8.8          0.0     0.535  1.0         2   ol   \n",
       "\n",
       "   in_service  \n",
       "0        True  \n",
       "1        True  \n",
       "2        True  \n",
       "3        True  \n",
       "4        True  \n",
       "5        True  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# create lines\n",
    "for _, hv_line in hv_lines.iterrows():\n",
    "        from_bus = pp.get_element_index(net, \"bus\", hv_line.from_bus)\n",
    "        to_bus = pp.get_element_index(net, \"bus\", hv_line.to_bus)\n",
    "        pp.create_line(net, from_bus, to_bus, length_km=hv_line.length,std_type=hv_line.std_type, name=hv_line.line_name, parallel=hv_line.parallel)\n",
    "\n",
    "# show line table\n",
    "net.line"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Transformer\n",
    "\n",
    "<img src=\"pics/example_network_trafos_hv.png\" width=\"40%\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The 380/110 kV transformer connects the buses \"Bus DB 1\" and \"Bus DB 2\". We use the get_element_index function from the pandapower toolbox to find the bus indices of the buses with these names and create a transformer by directly specifying the parameters:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>std_type</th>\n",
       "      <th>hv_bus</th>\n",
       "      <th>lv_bus</th>\n",
       "      <th>sn_mva</th>\n",
       "      <th>vn_hv_kv</th>\n",
       "      <th>vn_lv_kv</th>\n",
       "      <th>vk_percent</th>\n",
       "      <th>vkr_percent</th>\n",
       "      <th>pfe_kw</th>\n",
       "      <th>...</th>\n",
       "      <th>tap_neutral</th>\n",
       "      <th>tap_min</th>\n",
       "      <th>tap_max</th>\n",
       "      <th>tap_step_percent</th>\n",
       "      <th>tap_step_degree</th>\n",
       "      <th>tap_pos</th>\n",
       "      <th>tap_phase_shifter</th>\n",
       "      <th>parallel</th>\n",
       "      <th>df</th>\n",
       "      <th>in_service</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>EHV-HV-Trafo</td>\n",
       "      <td>None</td>\n",
       "      <td>13</td>\n",
       "      <td>17</td>\n",
       "      <td>300.0</td>\n",
       "      <td>380.0</td>\n",
       "      <td>110.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>0.06</td>\n",
       "      <td>0.0</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>False</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1 rows × 23 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           name std_type  hv_bus  lv_bus  sn_mva  vn_hv_kv  vn_lv_kv  \\\n",
       "0  EHV-HV-Trafo     None      13      17   300.0     380.0     110.0   \n",
       "\n",
       "   vk_percent  vkr_percent  pfe_kw     ...      tap_neutral  tap_min tap_max  \\\n",
       "0         8.0         0.06     0.0     ...              NaN      NaN     NaN   \n",
       "\n",
       "   tap_step_percent  tap_step_degree  tap_pos  tap_phase_shifter  parallel  \\\n",
       "0               NaN              NaN      NaN              False         1   \n",
       "\n",
       "    df  in_service  \n",
       "0  1.0        True  \n",
       "\n",
       "[1 rows x 23 columns]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hv_bus = pp.get_element_index(net, \"bus\", \"Bus DB 2\")\n",
    "lv_bus = pp.get_element_index(net, \"bus\", \"Bus SB 1\")\n",
    "pp.create_transformer_from_parameters(net, hv_bus, lv_bus, sn_mva=300, vn_hv_kv=380, vn_lv_kv=110, vkr_percent=0.06,\n",
    "                                      vk_percent=8, pfe_kw=0, i0_percent=0, tp_pos=0, shift_degree=0, name='EHV-HV-Trafo')\n",
    "\n",
    "net.trafo # show trafo table"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Switches\n",
    "\n",
    "<img src=\"pics/example_network_switches_hv.png\" width=\"60%\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now we create the switches to connect the buses in the transformer station. The switch configuration is stored in the following csv table:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>bus_name</th>\n",
       "      <th>from_bus</th>\n",
       "      <th>to_bus</th>\n",
       "      <th>type</th>\n",
       "      <th>et</th>\n",
       "      <th>closed</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>DB DS0</td>\n",
       "      <td>Double Busbar 2</td>\n",
       "      <td>Bus DB T0</td>\n",
       "      <td>DS</td>\n",
       "      <td>b</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>DB DS1</td>\n",
       "      <td>Double Busbar 1</td>\n",
       "      <td>Bus DB T1</td>\n",
       "      <td>DS</td>\n",
       "      <td>b</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>DB DS2</td>\n",
       "      <td>Double Busbar 2</td>\n",
       "      <td>Bus DB T3</td>\n",
       "      <td>DS</td>\n",
       "      <td>b</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>DB DS3</td>\n",
       "      <td>Double Busbar 1</td>\n",
       "      <td>Bus DB T3</td>\n",
       "      <td>DS</td>\n",
       "      <td>b</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>DB DS4</td>\n",
       "      <td>Double Busbar 2</td>\n",
       "      <td>Bus DB T5</td>\n",
       "      <td>DS</td>\n",
       "      <td>b</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>DB DS5</td>\n",
       "      <td>Double Busbar 1</td>\n",
       "      <td>Bus DB T5</td>\n",
       "      <td>DS</td>\n",
       "      <td>b</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>DB DS6</td>\n",
       "      <td>Double Busbar 2</td>\n",
       "      <td>Bus DB T7</td>\n",
       "      <td>DS</td>\n",
       "      <td>b</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>DB DS7</td>\n",
       "      <td>Double Busbar 1</td>\n",
       "      <td>Bus DB T7</td>\n",
       "      <td>DS</td>\n",
       "      <td>b</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>DB DS8</td>\n",
       "      <td>Double Busbar 2</td>\n",
       "      <td>Bus DB T9</td>\n",
       "      <td>DS</td>\n",
       "      <td>b</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>DB DS9</td>\n",
       "      <td>Double Busbar 1</td>\n",
       "      <td>Bus DB T9</td>\n",
       "      <td>DS</td>\n",
       "      <td>b</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>DB DS10</td>\n",
       "      <td>Bus DB T2</td>\n",
       "      <td>Bus DB 1</td>\n",
       "      <td>DS</td>\n",
       "      <td>b</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>DB DS11</td>\n",
       "      <td>Bus DB T4</td>\n",
       "      <td>Bus DB 2</td>\n",
       "      <td>DS</td>\n",
       "      <td>b</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>DB DS12</td>\n",
       "      <td>Bus DB T6</td>\n",
       "      <td>Bus DB 3</td>\n",
       "      <td>DS</td>\n",
       "      <td>b</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>DB DS13</td>\n",
       "      <td>Bus DB T8</td>\n",
       "      <td>Bus DB 4</td>\n",
       "      <td>DS</td>\n",
       "      <td>b</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>DB CB0</td>\n",
       "      <td>Bus DB T0</td>\n",
       "      <td>Bus DB T1</td>\n",
       "      <td>CB</td>\n",
       "      <td>b</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>DB CB1</td>\n",
       "      <td>Bus DB T3</td>\n",
       "      <td>Bus DB T2</td>\n",
       "      <td>CB</td>\n",
       "      <td>b</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>DB CB2</td>\n",
       "      <td>Bus DB T5</td>\n",
       "      <td>Bus DB T4</td>\n",
       "      <td>CB</td>\n",
       "      <td>b</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>DB CB3</td>\n",
       "      <td>Bus DB T7</td>\n",
       "      <td>Bus DB T6</td>\n",
       "      <td>CB</td>\n",
       "      <td>b</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>DB CB4</td>\n",
       "      <td>Bus DB T9</td>\n",
       "      <td>Bus DB T8</td>\n",
       "      <td>CB</td>\n",
       "      <td>b</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>SB DS1.1</td>\n",
       "      <td>Bus SB T1.1</td>\n",
       "      <td>Bus SB 1</td>\n",
       "      <td>DS</td>\n",
       "      <td>b</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>SB DS1.2</td>\n",
       "      <td>Single Busbar</td>\n",
       "      <td>Bus SB T1.2</td>\n",
       "      <td>DS</td>\n",
       "      <td>b</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>SB DS2.1</td>\n",
       "      <td>Bus SB T2.1</td>\n",
       "      <td>Bus SB 2</td>\n",
       "      <td>DS</td>\n",
       "      <td>b</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>SB DS2.2</td>\n",
       "      <td>Single Busbar</td>\n",
       "      <td>Bus SB T2.2</td>\n",
       "      <td>DS</td>\n",
       "      <td>b</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>SB DS3.1</td>\n",
       "      <td>Bus SB T3.1</td>\n",
       "      <td>Bus SB 3</td>\n",
       "      <td>DS</td>\n",
       "      <td>b</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>SB DS3.2</td>\n",
       "      <td>Single Busbar</td>\n",
       "      <td>Bus SB T3.2</td>\n",
       "      <td>DS</td>\n",
       "      <td>b</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>SB DS4.1</td>\n",
       "      <td>Bus SB T4.1</td>\n",
       "      <td>Bus SB 4</td>\n",
       "      <td>DS</td>\n",
       "      <td>b</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>SB DS4.2</td>\n",
       "      <td>Single Busbar</td>\n",
       "      <td>Bus SB T4.2</td>\n",
       "      <td>DS</td>\n",
       "      <td>b</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>SB DS5.1</td>\n",
       "      <td>Bus SB T5.1</td>\n",
       "      <td>Bus SB 5</td>\n",
       "      <td>DS</td>\n",
       "      <td>b</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>SB DS5.2</td>\n",
       "      <td>Single Busbar</td>\n",
       "      <td>Bus SB T5.2</td>\n",
       "      <td>DS</td>\n",
       "      <td>b</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>SB CB1</td>\n",
       "      <td>Bus SB T1.2</td>\n",
       "      <td>Bus SB T1.1</td>\n",
       "      <td>CB</td>\n",
       "      <td>b</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>SB CB2</td>\n",
       "      <td>Bus SB T2.2</td>\n",
       "      <td>Bus SB T2.1</td>\n",
       "      <td>CB</td>\n",
       "      <td>b</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>SB CB3</td>\n",
       "      <td>Bus SB T3.2</td>\n",
       "      <td>Bus SB T3.1</td>\n",
       "      <td>CB</td>\n",
       "      <td>b</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>SB CB4</td>\n",
       "      <td>Bus SB T4.2</td>\n",
       "      <td>Bus SB T4.1</td>\n",
       "      <td>CB</td>\n",
       "      <td>b</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>SB CB5</td>\n",
       "      <td>Bus SB T5.2</td>\n",
       "      <td>Bus SB T5.1</td>\n",
       "      <td>CB</td>\n",
       "      <td>b</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    bus_name         from_bus       to_bus type et  closed\n",
       "0     DB DS0  Double Busbar 2    Bus DB T0   DS  b    True\n",
       "1     DB DS1  Double Busbar 1    Bus DB T1   DS  b    True\n",
       "2     DB DS2  Double Busbar 2    Bus DB T3   DS  b    True\n",
       "3     DB DS3  Double Busbar 1    Bus DB T3   DS  b   False\n",
       "4     DB DS4  Double Busbar 2    Bus DB T5   DS  b    True\n",
       "5     DB DS5  Double Busbar 1    Bus DB T5   DS  b   False\n",
       "6     DB DS6  Double Busbar 2    Bus DB T7   DS  b    True\n",
       "7     DB DS7  Double Busbar 1    Bus DB T7   DS  b   False\n",
       "8     DB DS8  Double Busbar 2    Bus DB T9   DS  b    True\n",
       "9     DB DS9  Double Busbar 1    Bus DB T9   DS  b   False\n",
       "10   DB DS10        Bus DB T2     Bus DB 1   DS  b    True\n",
       "11   DB DS11        Bus DB T4     Bus DB 2   DS  b    True\n",
       "12   DB DS12        Bus DB T6     Bus DB 3   DS  b    True\n",
       "13   DB DS13        Bus DB T8     Bus DB 4   DS  b    True\n",
       "14    DB CB0        Bus DB T0    Bus DB T1   CB  b    True\n",
       "15    DB CB1        Bus DB T3    Bus DB T2   CB  b    True\n",
       "16    DB CB2        Bus DB T5    Bus DB T4   CB  b    True\n",
       "17    DB CB3        Bus DB T7    Bus DB T6   CB  b    True\n",
       "18    DB CB4        Bus DB T9    Bus DB T8   CB  b    True\n",
       "19  SB DS1.1      Bus SB T1.1     Bus SB 1   DS  b    True\n",
       "20  SB DS1.2    Single Busbar  Bus SB T1.2   DS  b    True\n",
       "21  SB DS2.1      Bus SB T2.1     Bus SB 2   DS  b    True\n",
       "22  SB DS2.2    Single Busbar  Bus SB T2.2   DS  b    True\n",
       "23  SB DS3.1      Bus SB T3.1     Bus SB 3   DS  b    True\n",
       "24  SB DS3.2    Single Busbar  Bus SB T3.2   DS  b    True\n",
       "25  SB DS4.1      Bus SB T4.1     Bus SB 4   DS  b    True\n",
       "26  SB DS4.2    Single Busbar  Bus SB T4.2   DS  b    True\n",
       "27  SB DS5.1      Bus SB T5.1     Bus SB 5   DS  b    True\n",
       "28  SB DS5.2    Single Busbar  Bus SB T5.2   DS  b    True\n",
       "29    SB CB1      Bus SB T1.2  Bus SB T1.1   CB  b    True\n",
       "30    SB CB2      Bus SB T2.2  Bus SB T2.1   CB  b    True\n",
       "31    SB CB3      Bus SB T3.2  Bus SB T3.1   CB  b    True\n",
       "32    SB CB4      Bus SB T4.2  Bus SB T4.1   CB  b    True\n",
       "33    SB CB5      Bus SB T5.2  Bus SB T5.1   CB  b    True"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hv_bus_sw = pd.read_csv('example_advanced/hv_bus_sw.csv', sep=';', header=0, decimal=',')\n",
    "hv_bus_sw"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>bus</th>\n",
       "      <th>element</th>\n",
       "      <th>et</th>\n",
       "      <th>type</th>\n",
       "      <th>closed</th>\n",
       "      <th>name</th>\n",
       "      <th>z_ohm</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>b</td>\n",
       "      <td>DS</td>\n",
       "      <td>True</td>\n",
       "      <td>DB DS0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>b</td>\n",
       "      <td>DS</td>\n",
       "      <td>True</td>\n",
       "      <td>DB DS1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "      <td>b</td>\n",
       "      <td>DS</td>\n",
       "      <td>True</td>\n",
       "      <td>DB DS2</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "      <td>b</td>\n",
       "      <td>DS</td>\n",
       "      <td>False</td>\n",
       "      <td>DB DS3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>7</td>\n",
       "      <td>b</td>\n",
       "      <td>DS</td>\n",
       "      <td>True</td>\n",
       "      <td>DB DS4</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0</td>\n",
       "      <td>7</td>\n",
       "      <td>b</td>\n",
       "      <td>DS</td>\n",
       "      <td>False</td>\n",
       "      <td>DB DS5</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1</td>\n",
       "      <td>9</td>\n",
       "      <td>b</td>\n",
       "      <td>DS</td>\n",
       "      <td>True</td>\n",
       "      <td>DB DS6</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>b</td>\n",
       "      <td>DS</td>\n",
       "      <td>False</td>\n",
       "      <td>DB DS7</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>1</td>\n",
       "      <td>11</td>\n",
       "      <td>b</td>\n",
       "      <td>DS</td>\n",
       "      <td>True</td>\n",
       "      <td>DB DS8</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>0</td>\n",
       "      <td>11</td>\n",
       "      <td>b</td>\n",
       "      <td>DS</td>\n",
       "      <td>False</td>\n",
       "      <td>DB DS9</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>4</td>\n",
       "      <td>12</td>\n",
       "      <td>b</td>\n",
       "      <td>DS</td>\n",
       "      <td>True</td>\n",
       "      <td>DB DS10</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>6</td>\n",
       "      <td>13</td>\n",
       "      <td>b</td>\n",
       "      <td>DS</td>\n",
       "      <td>True</td>\n",
       "      <td>DB DS11</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>8</td>\n",
       "      <td>14</td>\n",
       "      <td>b</td>\n",
       "      <td>DS</td>\n",
       "      <td>True</td>\n",
       "      <td>DB DS12</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>10</td>\n",
       "      <td>15</td>\n",
       "      <td>b</td>\n",
       "      <td>DS</td>\n",
       "      <td>True</td>\n",
       "      <td>DB DS13</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>b</td>\n",
       "      <td>CB</td>\n",
       "      <td>True</td>\n",
       "      <td>DB CB0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>5</td>\n",
       "      <td>4</td>\n",
       "      <td>b</td>\n",
       "      <td>CB</td>\n",
       "      <td>True</td>\n",
       "      <td>DB CB1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>7</td>\n",
       "      <td>6</td>\n",
       "      <td>b</td>\n",
       "      <td>CB</td>\n",
       "      <td>True</td>\n",
       "      <td>DB CB2</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>9</td>\n",
       "      <td>8</td>\n",
       "      <td>b</td>\n",
       "      <td>CB</td>\n",
       "      <td>True</td>\n",
       "      <td>DB CB3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>11</td>\n",
       "      <td>10</td>\n",
       "      <td>b</td>\n",
       "      <td>CB</td>\n",
       "      <td>True</td>\n",
       "      <td>DB CB4</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>22</td>\n",
       "      <td>17</td>\n",
       "      <td>b</td>\n",
       "      <td>DS</td>\n",
       "      <td>True</td>\n",
       "      <td>SB DS1.1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>16</td>\n",
       "      <td>23</td>\n",
       "      <td>b</td>\n",
       "      <td>DS</td>\n",
       "      <td>True</td>\n",
       "      <td>SB DS1.2</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>24</td>\n",
       "      <td>18</td>\n",
       "      <td>b</td>\n",
       "      <td>DS</td>\n",
       "      <td>True</td>\n",
       "      <td>SB DS2.1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>16</td>\n",
       "      <td>25</td>\n",
       "      <td>b</td>\n",
       "      <td>DS</td>\n",
       "      <td>True</td>\n",
       "      <td>SB DS2.2</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>26</td>\n",
       "      <td>19</td>\n",
       "      <td>b</td>\n",
       "      <td>DS</td>\n",
       "      <td>True</td>\n",
       "      <td>SB DS3.1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>16</td>\n",
       "      <td>27</td>\n",
       "      <td>b</td>\n",
       "      <td>DS</td>\n",
       "      <td>True</td>\n",
       "      <td>SB DS3.2</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>28</td>\n",
       "      <td>20</td>\n",
       "      <td>b</td>\n",
       "      <td>DS</td>\n",
       "      <td>True</td>\n",
       "      <td>SB DS4.1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>16</td>\n",
       "      <td>29</td>\n",
       "      <td>b</td>\n",
       "      <td>DS</td>\n",
       "      <td>True</td>\n",
       "      <td>SB DS4.2</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>30</td>\n",
       "      <td>21</td>\n",
       "      <td>b</td>\n",
       "      <td>DS</td>\n",
       "      <td>True</td>\n",
       "      <td>SB DS5.1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>16</td>\n",
       "      <td>31</td>\n",
       "      <td>b</td>\n",
       "      <td>DS</td>\n",
       "      <td>True</td>\n",
       "      <td>SB DS5.2</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>23</td>\n",
       "      <td>22</td>\n",
       "      <td>b</td>\n",
       "      <td>CB</td>\n",
       "      <td>True</td>\n",
       "      <td>SB CB1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>25</td>\n",
       "      <td>24</td>\n",
       "      <td>b</td>\n",
       "      <td>CB</td>\n",
       "      <td>True</td>\n",
       "      <td>SB CB2</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>27</td>\n",
       "      <td>26</td>\n",
       "      <td>b</td>\n",
       "      <td>CB</td>\n",
       "      <td>True</td>\n",
       "      <td>SB CB3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>29</td>\n",
       "      <td>28</td>\n",
       "      <td>b</td>\n",
       "      <td>CB</td>\n",
       "      <td>True</td>\n",
       "      <td>SB CB4</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>31</td>\n",
       "      <td>30</td>\n",
       "      <td>b</td>\n",
       "      <td>CB</td>\n",
       "      <td>True</td>\n",
       "      <td>SB CB5</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>18</td>\n",
       "      <td>0</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus SB 2 - HV Line1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>32</td>\n",
       "      <td>0</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus HV1 - HV Line1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>32</td>\n",
       "      <td>1</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus HV1 - HV Line2</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>33</td>\n",
       "      <td>1</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus HV2 - HV Line2</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>33</td>\n",
       "      <td>2</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus HV2 - HV Line3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>35</td>\n",
       "      <td>2</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus HV4 - HV Line3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>32</td>\n",
       "      <td>3</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus HV1 - HV Line4</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>35</td>\n",
       "      <td>3</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus HV4 - HV Line4</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42</th>\n",
       "      <td>34</td>\n",
       "      <td>4</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus HV3 - HV Line5</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43</th>\n",
       "      <td>35</td>\n",
       "      <td>4</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus HV4 - HV Line5</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44</th>\n",
       "      <td>19</td>\n",
       "      <td>5</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus SB 3 - HV Line6</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45</th>\n",
       "      <td>34</td>\n",
       "      <td>5</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus HV3 - HV Line6</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46</th>\n",
       "      <td>13</td>\n",
       "      <td>0</td>\n",
       "      <td>t</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch DB2 - EHV-HV-Trafo</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47</th>\n",
       "      <td>17</td>\n",
       "      <td>0</td>\n",
       "      <td>t</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch SB1 - EHV-HV-Trafo</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    bus  element et type  closed                        name  z_ohm\n",
       "0     1        2  b   DS    True                      DB DS0    0.0\n",
       "1     0        3  b   DS    True                      DB DS1    0.0\n",
       "2     1        5  b   DS    True                      DB DS2    0.0\n",
       "3     0        5  b   DS   False                      DB DS3    0.0\n",
       "4     1        7  b   DS    True                      DB DS4    0.0\n",
       "5     0        7  b   DS   False                      DB DS5    0.0\n",
       "6     1        9  b   DS    True                      DB DS6    0.0\n",
       "7     0        9  b   DS   False                      DB DS7    0.0\n",
       "8     1       11  b   DS    True                      DB DS8    0.0\n",
       "9     0       11  b   DS   False                      DB DS9    0.0\n",
       "10    4       12  b   DS    True                     DB DS10    0.0\n",
       "11    6       13  b   DS    True                     DB DS11    0.0\n",
       "12    8       14  b   DS    True                     DB DS12    0.0\n",
       "13   10       15  b   DS    True                     DB DS13    0.0\n",
       "14    2        3  b   CB    True                      DB CB0    0.0\n",
       "15    5        4  b   CB    True                      DB CB1    0.0\n",
       "16    7        6  b   CB    True                      DB CB2    0.0\n",
       "17    9        8  b   CB    True                      DB CB3    0.0\n",
       "18   11       10  b   CB    True                      DB CB4    0.0\n",
       "19   22       17  b   DS    True                    SB DS1.1    0.0\n",
       "20   16       23  b   DS    True                    SB DS1.2    0.0\n",
       "21   24       18  b   DS    True                    SB DS2.1    0.0\n",
       "22   16       25  b   DS    True                    SB DS2.2    0.0\n",
       "23   26       19  b   DS    True                    SB DS3.1    0.0\n",
       "24   16       27  b   DS    True                    SB DS3.2    0.0\n",
       "25   28       20  b   DS    True                    SB DS4.1    0.0\n",
       "26   16       29  b   DS    True                    SB DS4.2    0.0\n",
       "27   30       21  b   DS    True                    SB DS5.1    0.0\n",
       "28   16       31  b   DS    True                    SB DS5.2    0.0\n",
       "29   23       22  b   CB    True                      SB CB1    0.0\n",
       "30   25       24  b   CB    True                      SB CB2    0.0\n",
       "31   27       26  b   CB    True                      SB CB3    0.0\n",
       "32   29       28  b   CB    True                      SB CB4    0.0\n",
       "33   31       30  b   CB    True                      SB CB5    0.0\n",
       "34   18        0  l  LBS    True  Switch Bus SB 2 - HV Line1    0.0\n",
       "35   32        0  l  LBS    True   Switch Bus HV1 - HV Line1    0.0\n",
       "36   32        1  l  LBS    True   Switch Bus HV1 - HV Line2    0.0\n",
       "37   33        1  l  LBS    True   Switch Bus HV2 - HV Line2    0.0\n",
       "38   33        2  l  LBS    True   Switch Bus HV2 - HV Line3    0.0\n",
       "39   35        2  l  LBS    True   Switch Bus HV4 - HV Line3    0.0\n",
       "40   32        3  l  LBS    True   Switch Bus HV1 - HV Line4    0.0\n",
       "41   35        3  l  LBS    True   Switch Bus HV4 - HV Line4    0.0\n",
       "42   34        4  l  LBS    True   Switch Bus HV3 - HV Line5    0.0\n",
       "43   35        4  l  LBS    True   Switch Bus HV4 - HV Line5    0.0\n",
       "44   19        5  l  LBS    True  Switch Bus SB 3 - HV Line6    0.0\n",
       "45   34        5  l  LBS    True   Switch Bus HV3 - HV Line6    0.0\n",
       "46   13        0  t  LBS    True   Switch DB2 - EHV-HV-Trafo    0.0\n",
       "47   17        0  t  LBS    True   Switch SB1 - EHV-HV-Trafo    0.0"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Bus-bus switches\n",
    "for _, switch in hv_bus_sw.iterrows():\n",
    "    from_bus = pp.get_element_index(net, \"bus\", switch.from_bus)\n",
    "    to_bus = pp.get_element_index(net, \"bus\", switch.to_bus)\n",
    "    pp.create_switch(net, from_bus, to_bus, et=switch.et, closed=switch.closed, type=switch.type, name=switch.bus_name)\n",
    "\n",
    "# Bus-line switches\n",
    "hv_buses = net.bus[(net.bus.vn_kv == 380) | (net.bus.vn_kv == 110)].index\n",
    "hv_ls = net.line[(net.line.from_bus.isin(hv_buses)) & (net.line.to_bus.isin(hv_buses))]\n",
    "for _, line in hv_ls.iterrows():\n",
    "        pp.create_switch(net, line.from_bus, line.name, et='l', closed=True, type='LBS', name='Switch %s - %s' % (net.bus.name.at[line.from_bus], line['name']))\n",
    "        pp.create_switch(net, line.to_bus, line.name, et='l', closed=True, type='LBS', name='Switch %s - %s' % (net.bus.name.at[line.to_bus], line['name']))\n",
    "\n",
    "# Trafo-line switches\n",
    "pp.create_switch(net, pp.get_element_index(net, \"bus\", 'Bus DB 2'), pp.get_element_index(net, \"trafo\", 'EHV-HV-Trafo'), et='t', closed=True, type='LBS', name='Switch DB2 - EHV-HV-Trafo')\n",
    "pp.create_switch(net, pp.get_element_index(net, \"bus\", 'Bus SB 1'), pp.get_element_index(net, \"trafo\", 'EHV-HV-Trafo'), et='t', closed=True, type='LBS', name='Switch SB1 - EHV-HV-Trafo')\n",
    "\n",
    "# show switch table\n",
    "net.switch"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### External Grid\n",
    "\n",
    "<img src=\"pics/example_network_ext_grids_hv.png\" width=\"40%\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We equip the high voltage side of the transformer with an external grid connection:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>bus</th>\n",
       "      <th>vm_pu</th>\n",
       "      <th>va_degree</th>\n",
       "      <th>in_service</th>\n",
       "      <th>s_sc_max_mva</th>\n",
       "      <th>rx_min</th>\n",
       "      <th>rx_max</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>External grid</td>\n",
       "      <td>0</td>\n",
       "      <td>1.03</td>\n",
       "      <td>0.0</td>\n",
       "      <td>True</td>\n",
       "      <td>10000.0</td>\n",
       "      <td>0.1</td>\n",
       "      <td>0.1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            name  bus  vm_pu  va_degree  in_service  s_sc_max_mva  rx_min  \\\n",
       "0  External grid    0   1.03        0.0        True       10000.0     0.1   \n",
       "\n",
       "   rx_max  \n",
       "0     0.1  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pp.create_ext_grid(net, pp.get_element_index(net, \"bus\", 'Double Busbar 1'), vm_pu=1.03, va_degree=0, name='External grid',\n",
    "                   s_sc_max_mva=10000, rx_max=0.1, rx_min=0.1)\n",
    "\n",
    "net.ext_grid # show external grid table"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Loads\n",
    "\n",
    "<img src=\"pics/example_network_loads_hv.png\" width=\"40%\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The five loads in the HV network are defined in the following csv file:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>load_name</th>\n",
       "      <th>bus</th>\n",
       "      <th>p</th>\n",
       "      <th>q</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>MV Net 0</td>\n",
       "      <td>Bus SB 4</td>\n",
       "      <td>38</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>MV Net 1</td>\n",
       "      <td>Bus HV1</td>\n",
       "      <td>38</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>MV Net 2</td>\n",
       "      <td>Bus HV2</td>\n",
       "      <td>38</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>MV Net 3</td>\n",
       "      <td>Bus HV3</td>\n",
       "      <td>38</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>MV Net 4</td>\n",
       "      <td>Bus HV4</td>\n",
       "      <td>38</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  load_name       bus   p  q\n",
       "0  MV Net 0  Bus SB 4  38  6\n",
       "1  MV Net 1   Bus HV1  38  6\n",
       "2  MV Net 2   Bus HV2  38  6\n",
       "3  MV Net 3   Bus HV3  38  6\n",
       "4  MV Net 4   Bus HV4  38  6"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hv_loads = pd.read_csv('example_advanced/hv_loads.csv', sep=';', header=0, decimal=',')\n",
    "hv_loads"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>bus</th>\n",
       "      <th>p_mw</th>\n",
       "      <th>q_mvar</th>\n",
       "      <th>const_z_percent</th>\n",
       "      <th>const_i_percent</th>\n",
       "      <th>sn_mva</th>\n",
       "      <th>scaling</th>\n",
       "      <th>in_service</th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>MV Net 0</td>\n",
       "      <td>20</td>\n",
       "      <td>38.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>MV Net 1</td>\n",
       "      <td>32</td>\n",
       "      <td>38.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>MV Net 2</td>\n",
       "      <td>33</td>\n",
       "      <td>38.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>MV Net 3</td>\n",
       "      <td>34</td>\n",
       "      <td>38.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>MV Net 4</td>\n",
       "      <td>35</td>\n",
       "      <td>38.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       name  bus  p_mw  q_mvar  const_z_percent  const_i_percent  sn_mva  \\\n",
       "0  MV Net 0   20  38.0     6.0              0.0              0.0     NaN   \n",
       "1  MV Net 1   32  38.0     6.0              0.0              0.0     NaN   \n",
       "2  MV Net 2   33  38.0     6.0              0.0              0.0     NaN   \n",
       "3  MV Net 3   34  38.0     6.0              0.0              0.0     NaN   \n",
       "4  MV Net 4   35  38.0     6.0              0.0              0.0     NaN   \n",
       "\n",
       "   scaling  in_service  type  \n",
       "0      1.0        True  None  \n",
       "1      1.0        True  None  \n",
       "2      1.0        True  None  \n",
       "3      1.0        True  None  \n",
       "4      1.0        True  None  "
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "for _, load in hv_loads.iterrows():\n",
    "    bus_idx = pp.get_element_index(net, \"bus\", load.bus)\n",
    "    pp.create_load(net, bus_idx, p_mw=load.p, q_mvar=load.q, name=load.load_name)\n",
    "\n",
    "# show load table\n",
    "net.load"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Generator\n",
    "\n",
    "<img src=\"pics/example_network_gens_hv.png\" width=\"40%\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The voltage controlled generator is created with an active power of 100 MW (negative for generation) and a voltage set point of 1.03 per unit:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>bus</th>\n",
       "      <th>p_mw</th>\n",
       "      <th>vm_pu</th>\n",
       "      <th>sn_mva</th>\n",
       "      <th>min_q_mvar</th>\n",
       "      <th>max_q_mvar</th>\n",
       "      <th>scaling</th>\n",
       "      <th>slack</th>\n",
       "      <th>in_service</th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Gas turbine</td>\n",
       "      <td>35</td>\n",
       "      <td>100.0</td>\n",
       "      <td>1.03</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          name  bus   p_mw  vm_pu  sn_mva  min_q_mvar  max_q_mvar  scaling  \\\n",
       "0  Gas turbine   35  100.0   1.03     NaN         NaN         NaN      1.0   \n",
       "\n",
       "   slack  in_service  type  \n",
       "0  False        True  None  "
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pp.create_gen(net, pp.get_element_index(net, \"bus\", 'Bus HV4'), vm_pu=1.03, p_mw=100, name='Gas turbine')\n",
    "\n",
    "# show generator table\n",
    "net.gen"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Static generators\n",
    "\n",
    "<img src=\"pics/example_network_sgens_hv.png\" width=\"40%\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We create this wind park with an active power of 20 MW (negative for generation) and a reactive power of -4 Mvar. To classify the generation as a wind park, we set type to \"WP\":"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>bus</th>\n",
       "      <th>p_mw</th>\n",
       "      <th>q_mvar</th>\n",
       "      <th>sn_mva</th>\n",
       "      <th>scaling</th>\n",
       "      <th>in_service</th>\n",
       "      <th>type</th>\n",
       "      <th>current_source</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Wind Park</td>\n",
       "      <td>21</td>\n",
       "      <td>20.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>45.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>WP</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        name  bus  p_mw  q_mvar  sn_mva  scaling  in_service type  \\\n",
       "0  Wind Park   21  20.0     4.0    45.0      1.0        True   WP   \n",
       "\n",
       "   current_source  \n",
       "0            True  "
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pp.create_sgen(net, pp.get_element_index(net, \"bus\", 'Bus SB 5'), p_mw=20, q_mvar=4, sn_mva=45, \n",
    "               type='WP', name='Wind Park')\n",
    "\n",
    "# show static generator table\n",
    "net.sgen"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Shunt\n",
    "\n",
    "<img src=\"pics/example_network_shunts_hv.png\" width=\"40%\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>bus</th>\n",
       "      <th>name</th>\n",
       "      <th>q_mvar</th>\n",
       "      <th>p_mw</th>\n",
       "      <th>vn_kv</th>\n",
       "      <th>step</th>\n",
       "      <th>max_step</th>\n",
       "      <th>in_service</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>32</td>\n",
       "      <td>Shunt</td>\n",
       "      <td>0.96</td>\n",
       "      <td>0.0</td>\n",
       "      <td>110.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   bus   name  q_mvar  p_mw  vn_kv  step  max_step  in_service\n",
       "0   32  Shunt    0.96   0.0  110.0     1         1        True"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pp.create_shunt(net, pp.get_element_index(net, \"bus\", 'Bus HV1'), p_mw=0, q_mvar=0.960, name='Shunt')\n",
    "\n",
    "# show shunt table\n",
    "net.shunt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### External network equivalents\n",
    "\n",
    "\n",
    "<img src=\"pics/example_network_ext_equi_hv.png\" width=\"40%\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The two remaining elements are impedances and extended ward equivalents:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>from_bus</th>\n",
       "      <th>to_bus</th>\n",
       "      <th>rft_pu</th>\n",
       "      <th>xft_pu</th>\n",
       "      <th>rtf_pu</th>\n",
       "      <th>xtf_pu</th>\n",
       "      <th>sn_mva</th>\n",
       "      <th>in_service</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Impedance</td>\n",
       "      <td>34</td>\n",
       "      <td>32</td>\n",
       "      <td>0.074873</td>\n",
       "      <td>0.198872</td>\n",
       "      <td>0.074873</td>\n",
       "      <td>0.198872</td>\n",
       "      <td>100.0</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        name  from_bus  to_bus    rft_pu    xft_pu    rtf_pu    xtf_pu  \\\n",
       "0  Impedance        34      32  0.074873  0.198872  0.074873  0.198872   \n",
       "\n",
       "   sn_mva  in_service  \n",
       "0   100.0        True  "
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Impedance\n",
    "pp.create_impedance(net, pp.get_element_index(net, \"bus\", 'Bus HV3'), pp.get_element_index(net, \"bus\", 'Bus HV1'), \n",
    "                    rft_pu=0.074873, xft_pu=0.198872, sn_mva=100, name='Impedance')\n",
    "\n",
    "# show impedance table\n",
    "net.impedance"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>bus</th>\n",
       "      <th>ps_mw</th>\n",
       "      <th>qs_mvar</th>\n",
       "      <th>qz_mvar</th>\n",
       "      <th>pz_mw</th>\n",
       "      <th>r_ohm</th>\n",
       "      <th>x_ohm</th>\n",
       "      <th>vm_pu</th>\n",
       "      <th>in_service</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>XWard 1</td>\n",
       "      <td>34</td>\n",
       "      <td>23.942</td>\n",
       "      <td>-12.241870</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.814571</td>\n",
       "      <td>0.0</td>\n",
       "      <td>12.18951</td>\n",
       "      <td>1.026160</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>XWard 2</td>\n",
       "      <td>32</td>\n",
       "      <td>3.776</td>\n",
       "      <td>-7.769979</td>\n",
       "      <td>0.0</td>\n",
       "      <td>9.174917</td>\n",
       "      <td>0.0</td>\n",
       "      <td>50.56217</td>\n",
       "      <td>1.024001</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      name  bus   ps_mw    qs_mvar  qz_mvar     pz_mw  r_ohm     x_ohm  \\\n",
       "0  XWard 1   34  23.942 -12.241870      0.0  2.814571    0.0  12.18951   \n",
       "1  XWard 2   32   3.776  -7.769979      0.0  9.174917    0.0  50.56217   \n",
       "\n",
       "      vm_pu  in_service  \n",
       "0  1.026160        True  \n",
       "1  1.024001        True  "
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# xwards\n",
    "pp.create_xward(net, pp.get_element_index(net, \"bus\", 'Bus HV3'), ps_mw=23.942, qs_mvar=-12.24187, pz_mw=2.814571, \n",
    "                qz_mvar=0, r_ohm=0, x_ohm=12.18951, vm_pu=1.02616, name='XWard 1')\n",
    "pp.create_xward(net, pp.get_element_index(net, \"bus\", 'Bus HV1'), ps_mw=3.776, qs_mvar=-7.769979, pz_mw=9.174917, \n",
    "                qz_mvar=0, r_ohm=0, x_ohm=50.56217, vm_pu=1.024001, name='XWard 2')\n",
    "\n",
    "# show xward table\n",
    "net.xward"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Medium voltage level"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Buses\n",
    "\n",
    "<img src=\"pics/example_network_buses_mv.png\" width=\"50%\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>vn_kv</th>\n",
       "      <th>type</th>\n",
       "      <th>zone</th>\n",
       "      <th>in_service</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>Bus MV0 20kV</td>\n",
       "      <td>20.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>Bus MV0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>Bus MV1</td>\n",
       "      <td>10.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>Bus MV2</td>\n",
       "      <td>10.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>Bus MV3</td>\n",
       "      <td>10.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>Bus MV4</td>\n",
       "      <td>10.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42</th>\n",
       "      <td>Bus MV5</td>\n",
       "      <td>10.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43</th>\n",
       "      <td>Bus MV6</td>\n",
       "      <td>10.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44</th>\n",
       "      <td>Bus MV7</td>\n",
       "      <td>10.0</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            name  vn_kv type  zone  in_service\n",
       "36  Bus MV0 20kV   20.0    n  None        True\n",
       "37       Bus MV0   10.0    n  None        True\n",
       "38       Bus MV1   10.0    n  None        True\n",
       "39       Bus MV2   10.0    n  None        True\n",
       "40       Bus MV3   10.0    n  None        True\n",
       "41       Bus MV4   10.0    n  None        True\n",
       "42       Bus MV5   10.0    n  None        True\n",
       "43       Bus MV6   10.0    n  None        True\n",
       "44       Bus MV7   10.0    n  None        True"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pp.create_bus(net, name='Bus MV0 20kV', vn_kv=20, type='n')\n",
    "for i in range(8):\n",
    "    pp.create_bus(net, name='Bus MV%s' % i, vn_kv=10, type='n')\n",
    "\n",
    "#show only medium voltage bus table\n",
    "mv_buses = net.bus[(net.bus.vn_kv == 10) | (net.bus.vn_kv == 20)]\n",
    "mv_buses"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Lines\n",
    "\n",
    "<img src=\"pics/example_network_lines_mv.png\" width=\"50%\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>std_type</th>\n",
       "      <th>from_bus</th>\n",
       "      <th>to_bus</th>\n",
       "      <th>length_km</th>\n",
       "      <th>r_ohm_per_km</th>\n",
       "      <th>x_ohm_per_km</th>\n",
       "      <th>c_nf_per_km</th>\n",
       "      <th>g_us_per_km</th>\n",
       "      <th>max_i_ka</th>\n",
       "      <th>df</th>\n",
       "      <th>parallel</th>\n",
       "      <th>type</th>\n",
       "      <th>in_service</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>MV Line1</td>\n",
       "      <td>NA2XS2Y 1x185 RM/25 12/20 kV</td>\n",
       "      <td>37</td>\n",
       "      <td>38</td>\n",
       "      <td>1.5</td>\n",
       "      <td>0.161</td>\n",
       "      <td>0.117</td>\n",
       "      <td>273.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.362</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>cs</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>MV Line2</td>\n",
       "      <td>NA2XS2Y 1x185 RM/25 12/20 kV</td>\n",
       "      <td>38</td>\n",
       "      <td>39</td>\n",
       "      <td>1.5</td>\n",
       "      <td>0.161</td>\n",
       "      <td>0.117</td>\n",
       "      <td>273.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.362</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>cs</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>MV Line3</td>\n",
       "      <td>NA2XS2Y 1x185 RM/25 12/20 kV</td>\n",
       "      <td>39</td>\n",
       "      <td>40</td>\n",
       "      <td>1.5</td>\n",
       "      <td>0.161</td>\n",
       "      <td>0.117</td>\n",
       "      <td>273.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.362</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>cs</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>MV Line4</td>\n",
       "      <td>NA2XS2Y 1x185 RM/25 12/20 kV</td>\n",
       "      <td>40</td>\n",
       "      <td>41</td>\n",
       "      <td>1.5</td>\n",
       "      <td>0.161</td>\n",
       "      <td>0.117</td>\n",
       "      <td>273.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.362</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>cs</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>MV Line5</td>\n",
       "      <td>NA2XS2Y 1x185 RM/25 12/20 kV</td>\n",
       "      <td>41</td>\n",
       "      <td>42</td>\n",
       "      <td>1.5</td>\n",
       "      <td>0.161</td>\n",
       "      <td>0.117</td>\n",
       "      <td>273.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.362</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>cs</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>MV Line6</td>\n",
       "      <td>NA2XS2Y 1x185 RM/25 12/20 kV</td>\n",
       "      <td>42</td>\n",
       "      <td>43</td>\n",
       "      <td>1.5</td>\n",
       "      <td>0.161</td>\n",
       "      <td>0.117</td>\n",
       "      <td>273.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.362</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>cs</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>MV Line7</td>\n",
       "      <td>NA2XS2Y 1x185 RM/25 12/20 kV</td>\n",
       "      <td>43</td>\n",
       "      <td>44</td>\n",
       "      <td>1.5</td>\n",
       "      <td>0.161</td>\n",
       "      <td>0.117</td>\n",
       "      <td>273.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.362</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>cs</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>MV Line8</td>\n",
       "      <td>NA2XS2Y 1x185 RM/25 12/20 kV</td>\n",
       "      <td>37</td>\n",
       "      <td>44</td>\n",
       "      <td>1.5</td>\n",
       "      <td>0.161</td>\n",
       "      <td>0.117</td>\n",
       "      <td>273.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.362</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>cs</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        name                      std_type  from_bus  to_bus  length_km  \\\n",
       "6   MV Line1  NA2XS2Y 1x185 RM/25 12/20 kV        37      38        1.5   \n",
       "7   MV Line2  NA2XS2Y 1x185 RM/25 12/20 kV        38      39        1.5   \n",
       "8   MV Line3  NA2XS2Y 1x185 RM/25 12/20 kV        39      40        1.5   \n",
       "9   MV Line4  NA2XS2Y 1x185 RM/25 12/20 kV        40      41        1.5   \n",
       "10  MV Line5  NA2XS2Y 1x185 RM/25 12/20 kV        41      42        1.5   \n",
       "11  MV Line6  NA2XS2Y 1x185 RM/25 12/20 kV        42      43        1.5   \n",
       "12  MV Line7  NA2XS2Y 1x185 RM/25 12/20 kV        43      44        1.5   \n",
       "13  MV Line8  NA2XS2Y 1x185 RM/25 12/20 kV        37      44        1.5   \n",
       "\n",
       "    r_ohm_per_km  x_ohm_per_km  c_nf_per_km  g_us_per_km  max_i_ka   df  \\\n",
       "6          0.161         0.117        273.0          0.0     0.362  1.0   \n",
       "7          0.161         0.117        273.0          0.0     0.362  1.0   \n",
       "8          0.161         0.117        273.0          0.0     0.362  1.0   \n",
       "9          0.161         0.117        273.0          0.0     0.362  1.0   \n",
       "10         0.161         0.117        273.0          0.0     0.362  1.0   \n",
       "11         0.161         0.117        273.0          0.0     0.362  1.0   \n",
       "12         0.161         0.117        273.0          0.0     0.362  1.0   \n",
       "13         0.161         0.117        273.0          0.0     0.362  1.0   \n",
       "\n",
       "    parallel type  in_service  \n",
       "6          1   cs        True  \n",
       "7          1   cs        True  \n",
       "8          1   cs        True  \n",
       "9          1   cs        True  \n",
       "10         1   cs        True  \n",
       "11         1   cs        True  \n",
       "12         1   cs        True  \n",
       "13         1   cs        True  "
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mv_lines = pd.read_csv('example_advanced/mv_lines.csv', sep=';', header=0, decimal=',')\n",
    "for _, mv_line in mv_lines.iterrows():\n",
    "    from_bus = pp.get_element_index(net, \"bus\", mv_line.from_bus)\n",
    "    to_bus = pp.get_element_index(net, \"bus\", mv_line.to_bus)\n",
    "    pp.create_line(net, from_bus, to_bus, length_km=mv_line.length, std_type=mv_line.std_type, name=mv_line.line_name)\n",
    "\n",
    "# show only medium voltage lines\n",
    "net.line[net.line.from_bus.isin(mv_buses.index)]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3 Winding Transformer\n",
    "\n",
    "<img src=\"pics/example_network_trafos_mv.png\" width=\"50%\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The three winding transformer transforms its high voltage level to two different lower voltage levels, in this case from 110 kV to 20 kV and 10 kV."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>std_type</th>\n",
       "      <th>hv_bus</th>\n",
       "      <th>mv_bus</th>\n",
       "      <th>lv_bus</th>\n",
       "      <th>sn_hv_mva</th>\n",
       "      <th>sn_mv_mva</th>\n",
       "      <th>sn_lv_mva</th>\n",
       "      <th>vn_hv_kv</th>\n",
       "      <th>vn_mv_kv</th>\n",
       "      <th>...</th>\n",
       "      <th>shift_lv_degree</th>\n",
       "      <th>tap_side</th>\n",
       "      <th>tap_neutral</th>\n",
       "      <th>tap_min</th>\n",
       "      <th>tap_max</th>\n",
       "      <th>tap_step_percent</th>\n",
       "      <th>tap_step_degree</th>\n",
       "      <th>tap_pos</th>\n",
       "      <th>tap_at_star_point</th>\n",
       "      <th>in_service</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>HV-MV-MV-Trafo</td>\n",
       "      <td>None</td>\n",
       "      <td>33</td>\n",
       "      <td>36</td>\n",
       "      <td>37</td>\n",
       "      <td>40.0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>25.0</td>\n",
       "      <td>110.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>...</td>\n",
       "      <td>30.0</td>\n",
       "      <td>hv</td>\n",
       "      <td>0</td>\n",
       "      <td>-8</td>\n",
       "      <td>8</td>\n",
       "      <td>1.25</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1 rows × 30 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             name std_type  hv_bus  mv_bus  lv_bus  sn_hv_mva  sn_mv_mva  \\\n",
       "0  HV-MV-MV-Trafo     None      33      36      37       40.0       15.0   \n",
       "\n",
       "   sn_lv_mva  vn_hv_kv  vn_mv_kv     ...      shift_lv_degree  tap_side  \\\n",
       "0       25.0     110.0      20.0     ...                 30.0        hv   \n",
       "\n",
       "   tap_neutral  tap_min  tap_max  tap_step_percent  tap_step_degree  tap_pos  \\\n",
       "0            0       -8        8              1.25              NaN        0   \n",
       "\n",
       "   tap_at_star_point  in_service  \n",
       "0              False        True  \n",
       "\n",
       "[1 rows x 30 columns]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hv_bus = pp.get_element_index(net, \"bus\", \"Bus HV2\")\n",
    "mv_bus = pp.get_element_index(net, \"bus\", \"Bus MV0 20kV\")\n",
    "lv_bus = pp.get_element_index(net, \"bus\", \"Bus MV0\")\n",
    "pp.create_transformer3w_from_parameters(net, hv_bus, mv_bus, lv_bus, vn_hv_kv=110, vn_mv_kv=20, vn_lv_kv=10, \n",
    "                                        sn_hv_mva=40, sn_mv_mva=15, sn_lv_mva=25, vk_hv_percent=10.1, \n",
    "                                        vk_mv_percent=10.1, vk_lv_percent=10.1, vkr_hv_percent=0.266667, \n",
    "                                        vkr_mv_percent=0.033333, vkr_lv_percent=0.04, pfe_kw=0, i0_percent=0, \n",
    "                                        shift_mv_degree=30, shift_lv_degree=30, tap_side=\"hv\", tap_neutral=0, tap_min=-8, \n",
    "                                        tap_max=8, tap_step_percent=1.25, tap_pos=0, name='HV-MV-MV-Trafo')\n",
    "\n",
    "# show transformer3w table\n",
    "net.trafo3w"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Switches"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>bus</th>\n",
       "      <th>element</th>\n",
       "      <th>et</th>\n",
       "      <th>type</th>\n",
       "      <th>closed</th>\n",
       "      <th>name</th>\n",
       "      <th>z_ohm</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>48</th>\n",
       "      <td>37</td>\n",
       "      <td>6</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus MV0 - MV Line1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>38</td>\n",
       "      <td>6</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus MV1 - MV Line1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50</th>\n",
       "      <td>38</td>\n",
       "      <td>7</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus MV1 - MV Line2</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>51</th>\n",
       "      <td>39</td>\n",
       "      <td>7</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus MV2 - MV Line2</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52</th>\n",
       "      <td>39</td>\n",
       "      <td>8</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus MV2 - MV Line3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>53</th>\n",
       "      <td>40</td>\n",
       "      <td>8</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus MV3 - MV Line3</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>54</th>\n",
       "      <td>40</td>\n",
       "      <td>9</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus MV3 - MV Line4</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>55</th>\n",
       "      <td>41</td>\n",
       "      <td>9</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus MV4 - MV Line4</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>56</th>\n",
       "      <td>41</td>\n",
       "      <td>10</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus MV4 - MV Line5</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>57</th>\n",
       "      <td>42</td>\n",
       "      <td>10</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>False</td>\n",
       "      <td>Switch Bus MV5 - MV Line5</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58</th>\n",
       "      <td>42</td>\n",
       "      <td>11</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus MV5 - MV Line6</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>59</th>\n",
       "      <td>43</td>\n",
       "      <td>11</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus MV6 - MV Line6</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <td>43</td>\n",
       "      <td>12</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus MV6 - MV Line7</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61</th>\n",
       "      <td>44</td>\n",
       "      <td>12</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus MV7 - MV Line7</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>62</th>\n",
       "      <td>37</td>\n",
       "      <td>13</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus MV0 - MV Line8</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>44</td>\n",
       "      <td>13</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus MV7 - MV Line8</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    bus  element et type  closed                       name  z_ohm\n",
       "48   37        6  l  LBS    True  Switch Bus MV0 - MV Line1    0.0\n",
       "49   38        6  l  LBS    True  Switch Bus MV1 - MV Line1    0.0\n",
       "50   38        7  l  LBS    True  Switch Bus MV1 - MV Line2    0.0\n",
       "51   39        7  l  LBS    True  Switch Bus MV2 - MV Line2    0.0\n",
       "52   39        8  l  LBS    True  Switch Bus MV2 - MV Line3    0.0\n",
       "53   40        8  l  LBS    True  Switch Bus MV3 - MV Line3    0.0\n",
       "54   40        9  l  LBS    True  Switch Bus MV3 - MV Line4    0.0\n",
       "55   41        9  l  LBS    True  Switch Bus MV4 - MV Line4    0.0\n",
       "56   41       10  l  LBS    True  Switch Bus MV4 - MV Line5    0.0\n",
       "57   42       10  l  LBS   False  Switch Bus MV5 - MV Line5    0.0\n",
       "58   42       11  l  LBS    True  Switch Bus MV5 - MV Line6    0.0\n",
       "59   43       11  l  LBS    True  Switch Bus MV6 - MV Line6    0.0\n",
       "60   43       12  l  LBS    True  Switch Bus MV6 - MV Line7    0.0\n",
       "61   44       12  l  LBS    True  Switch Bus MV7 - MV Line7    0.0\n",
       "62   37       13  l  LBS    True  Switch Bus MV0 - MV Line8    0.0\n",
       "63   44       13  l  LBS    True  Switch Bus MV7 - MV Line8    0.0"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Bus-line switches\n",
    "mv_buses = net.bus[(net.bus.vn_kv == 10) | (net.bus.vn_kv == 20)].index\n",
    "mv_ls = net.line[(net.line.from_bus.isin(mv_buses)) & (net.line.to_bus.isin(mv_buses))]\n",
    "for _, line in mv_ls.iterrows():\n",
    "        pp.create_switch(net, line.from_bus, line.name, et='l', closed=True, type='LBS', name='Switch %s - %s' % (net.bus.name.at[line.from_bus], line['name']))\n",
    "        pp.create_switch(net, line.to_bus, line.name, et='l', closed=True, type='LBS', name='Switch %s - %s' % (net.bus.name.at[line.to_bus], line['name']))\n",
    "\n",
    "# open switch\n",
    "open_switch_id = net.switch[(net.switch.name == 'Switch Bus MV5 - MV Line5')].index\n",
    "net.switch.closed.loc[open_switch_id] = False\n",
    "\n",
    "#show only medium voltage switch table\n",
    "net.switch[net.switch.bus.isin(mv_buses)]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Loads\n",
    "\n",
    "<img src=\"pics/example_network_loads_mv.png\"  width=\"50%\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>bus</th>\n",
       "      <th>p_mw</th>\n",
       "      <th>q_mvar</th>\n",
       "      <th>const_z_percent</th>\n",
       "      <th>const_i_percent</th>\n",
       "      <th>sn_mva</th>\n",
       "      <th>scaling</th>\n",
       "      <th>in_service</th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>Further MV-Rings</td>\n",
       "      <td>37</td>\n",
       "      <td>6.0</td>\n",
       "      <td>2.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Industry Load</td>\n",
       "      <td>36</td>\n",
       "      <td>18.0</td>\n",
       "      <td>4.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>LV Net 1</td>\n",
       "      <td>38</td>\n",
       "      <td>0.4</td>\n",
       "      <td>0.10</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>LV Net 2</td>\n",
       "      <td>39</td>\n",
       "      <td>0.4</td>\n",
       "      <td>0.06</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>LV Net 3</td>\n",
       "      <td>40</td>\n",
       "      <td>0.4</td>\n",
       "      <td>0.06</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>LV Net 5</td>\n",
       "      <td>42</td>\n",
       "      <td>0.4</td>\n",
       "      <td>0.06</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>LV Net 6</td>\n",
       "      <td>43</td>\n",
       "      <td>0.4</td>\n",
       "      <td>0.06</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>LV Net 7</td>\n",
       "      <td>44</td>\n",
       "      <td>0.4</td>\n",
       "      <td>0.06</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                name  bus  p_mw  q_mvar  const_z_percent  const_i_percent  \\\n",
       "5   Further MV-Rings   37   6.0    2.00              0.0              0.0   \n",
       "6      Industry Load   36  18.0    4.00              0.0              0.0   \n",
       "7           LV Net 1   38   0.4    0.10              0.0              0.0   \n",
       "8           LV Net 2   39   0.4    0.06              0.0              0.0   \n",
       "9           LV Net 3   40   0.4    0.06              0.0              0.0   \n",
       "10          LV Net 5   42   0.4    0.06              0.0              0.0   \n",
       "11          LV Net 6   43   0.4    0.06              0.0              0.0   \n",
       "12          LV Net 7   44   0.4    0.06              0.0              0.0   \n",
       "\n",
       "    sn_mva  scaling  in_service  type  \n",
       "5      NaN      1.0        True  None  \n",
       "6      NaN      1.0        True  None  \n",
       "7      NaN      1.0        True  None  \n",
       "8      NaN      1.0        True  None  \n",
       "9      NaN      1.0        True  None  \n",
       "10     NaN      1.0        True  None  \n",
       "11     NaN      1.0        True  None  \n",
       "12     NaN      1.0        True  None  "
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mv_loads = pd.read_csv('example_advanced/mv_loads.csv', sep=';', header=0, decimal=',')\n",
    "for _, load in mv_loads.iterrows():\n",
    "    bus_idx = pp.get_element_index(net, \"bus\", load.bus)\n",
    "    pp.create_load(net, bus_idx, p_mw=load.p, q_mvar=load.q, name=load.load_name)\n",
    "\n",
    "# show only medium voltage loads\n",
    "net.load[net.load.bus.isin(mv_buses)]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Static generators\n",
    "\n",
    "<img src=\"pics/example_network_sgens_mv.png\"  width=\"50%\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>bus</th>\n",
       "      <th>p_mw</th>\n",
       "      <th>q_mvar</th>\n",
       "      <th>sn_mva</th>\n",
       "      <th>scaling</th>\n",
       "      <th>in_service</th>\n",
       "      <th>type</th>\n",
       "      <th>current_source</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Biogas plant</td>\n",
       "      <td>43</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0.00</td>\n",
       "      <td>750.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>SGEN</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Further MV Generator</td>\n",
       "      <td>37</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0.05</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>SGEN</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Industry Generator</td>\n",
       "      <td>36</td>\n",
       "      <td>15.0</td>\n",
       "      <td>3.00</td>\n",
       "      <td>20000.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>SGEN</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>PV Park</td>\n",
       "      <td>42</td>\n",
       "      <td>2.0</td>\n",
       "      <td>0.10</td>\n",
       "      <td>5000.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>PV</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   name  bus  p_mw  q_mvar   sn_mva  scaling  in_service  \\\n",
       "1          Biogas plant   43   0.5    0.00    750.0      1.0        True   \n",
       "2  Further MV Generator   37   0.5    0.05   1000.0      1.0        True   \n",
       "3    Industry Generator   36  15.0    3.00  20000.0      1.0        True   \n",
       "4               PV Park   42   2.0    0.10   5000.0      1.0        True   \n",
       "\n",
       "   type  current_source  \n",
       "1  SGEN            True  \n",
       "2  SGEN            True  \n",
       "3  SGEN            True  \n",
       "4    PV            True  "
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mv_sgens = pd.read_csv('example_advanced/mv_sgens.csv', sep=';', header=0, decimal=',')\n",
    "for _, sgen in mv_sgens.iterrows():\n",
    "    bus_idx = pp.get_element_index(net, \"bus\", sgen.bus)\n",
    "    pp.create_sgen(net, bus_idx, p_mw=sgen.p, q_mvar=sgen.q, sn_mva=sgen.sn, type=sgen.type, name=sgen.sgen_name)\n",
    "\n",
    "# show only medium voltage static generators\n",
    "net.sgen[net.sgen.bus.isin(mv_buses)]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Low voltage level"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Busses\n",
    "\n",
    "<img src=\"pics/example_network_buses_lv.png\" width=\"50%\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>vn_kv</th>\n",
       "      <th>type</th>\n",
       "      <th>zone</th>\n",
       "      <th>in_service</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>45</th>\n",
       "      <td>Bus LV0</td>\n",
       "      <td>0.4</td>\n",
       "      <td>n</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46</th>\n",
       "      <td>Bus LV1.1</td>\n",
       "      <td>0.4</td>\n",
       "      <td>m</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47</th>\n",
       "      <td>Bus LV1.2</td>\n",
       "      <td>0.4</td>\n",
       "      <td>m</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>48</th>\n",
       "      <td>Bus LV1.3</td>\n",
       "      <td>0.4</td>\n",
       "      <td>m</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>Bus LV1.4</td>\n",
       "      <td>0.4</td>\n",
       "      <td>m</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50</th>\n",
       "      <td>Bus LV1.5</td>\n",
       "      <td>0.4</td>\n",
       "      <td>m</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>51</th>\n",
       "      <td>Bus LV2.1</td>\n",
       "      <td>0.4</td>\n",
       "      <td>m</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52</th>\n",
       "      <td>Bus LV2.2</td>\n",
       "      <td>0.4</td>\n",
       "      <td>m</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>53</th>\n",
       "      <td>Bus LV2.3</td>\n",
       "      <td>0.4</td>\n",
       "      <td>m</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>54</th>\n",
       "      <td>Bus LV2.4</td>\n",
       "      <td>0.4</td>\n",
       "      <td>m</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>55</th>\n",
       "      <td>Bus LV2.2.1</td>\n",
       "      <td>0.4</td>\n",
       "      <td>m</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>56</th>\n",
       "      <td>Bus LV2.2.2</td>\n",
       "      <td>0.4</td>\n",
       "      <td>m</td>\n",
       "      <td>None</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           name  vn_kv type  zone  in_service\n",
       "45      Bus LV0    0.4    n  None        True\n",
       "46    Bus LV1.1    0.4    m  None        True\n",
       "47    Bus LV1.2    0.4    m  None        True\n",
       "48    Bus LV1.3    0.4    m  None        True\n",
       "49    Bus LV1.4    0.4    m  None        True\n",
       "50    Bus LV1.5    0.4    m  None        True\n",
       "51    Bus LV2.1    0.4    m  None        True\n",
       "52    Bus LV2.2    0.4    m  None        True\n",
       "53    Bus LV2.3    0.4    m  None        True\n",
       "54    Bus LV2.4    0.4    m  None        True\n",
       "55  Bus LV2.2.1    0.4    m  None        True\n",
       "56  Bus LV2.2.2    0.4    m  None        True"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pp.create_bus(net, name='Bus LV0', vn_kv=0.4, type='n')\n",
    "for i in range(1, 6):\n",
    "    pp.create_bus(net, name='Bus LV1.%s' % i, vn_kv=0.4, type='m')\n",
    "for i in range(1, 5):\n",
    "    pp.create_bus(net, name='Bus LV2.%s' % i, vn_kv=0.4, type='m')\n",
    "pp.create_bus(net, name='Bus LV2.2.1', vn_kv=0.4, type='m')\n",
    "pp.create_bus(net, name='Bus LV2.2.2', vn_kv=0.4, type='m')\n",
    "\n",
    "# show only low voltage buses\n",
    "lv_buses = net.bus[net.bus.vn_kv == 0.4]\n",
    "lv_buses"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Lines\n",
    "\n",
    "<img src=\"pics/example_network_lines_lv.png\" width=\"50%\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>std_type</th>\n",
       "      <th>from_bus</th>\n",
       "      <th>to_bus</th>\n",
       "      <th>length_km</th>\n",
       "      <th>r_ohm_per_km</th>\n",
       "      <th>x_ohm_per_km</th>\n",
       "      <th>c_nf_per_km</th>\n",
       "      <th>g_us_per_km</th>\n",
       "      <th>max_i_ka</th>\n",
       "      <th>df</th>\n",
       "      <th>parallel</th>\n",
       "      <th>type</th>\n",
       "      <th>in_service</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>LV Line1.1</td>\n",
       "      <td>NAYY 4x120 SE</td>\n",
       "      <td>45</td>\n",
       "      <td>46</td>\n",
       "      <td>0.08</td>\n",
       "      <td>0.2250</td>\n",
       "      <td>0.08</td>\n",
       "      <td>264.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.242</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>cs</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>LV Line1.2</td>\n",
       "      <td>NAYY 4x120 SE</td>\n",
       "      <td>46</td>\n",
       "      <td>47</td>\n",
       "      <td>0.08</td>\n",
       "      <td>0.2250</td>\n",
       "      <td>0.08</td>\n",
       "      <td>264.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.242</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>cs</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>LV Line1.3</td>\n",
       "      <td>NAYY 4x120 SE</td>\n",
       "      <td>47</td>\n",
       "      <td>48</td>\n",
       "      <td>0.08</td>\n",
       "      <td>0.2250</td>\n",
       "      <td>0.08</td>\n",
       "      <td>264.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.242</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>cs</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>LV Line1.4</td>\n",
       "      <td>NAYY 4x120 SE</td>\n",
       "      <td>48</td>\n",
       "      <td>49</td>\n",
       "      <td>0.08</td>\n",
       "      <td>0.2250</td>\n",
       "      <td>0.08</td>\n",
       "      <td>264.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.242</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>cs</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>LV Line1.6</td>\n",
       "      <td>NAYY 4x120 SE</td>\n",
       "      <td>49</td>\n",
       "      <td>50</td>\n",
       "      <td>0.08</td>\n",
       "      <td>0.2250</td>\n",
       "      <td>0.08</td>\n",
       "      <td>264.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.242</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>cs</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>LV Line2.1</td>\n",
       "      <td>NAYY 4x120 SE</td>\n",
       "      <td>45</td>\n",
       "      <td>51</td>\n",
       "      <td>0.12</td>\n",
       "      <td>0.2250</td>\n",
       "      <td>0.08</td>\n",
       "      <td>264.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.242</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>cs</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>LV Line2.2</td>\n",
       "      <td>NAYY 4x120 SE</td>\n",
       "      <td>51</td>\n",
       "      <td>52</td>\n",
       "      <td>0.12</td>\n",
       "      <td>0.2250</td>\n",
       "      <td>0.08</td>\n",
       "      <td>264.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.242</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>cs</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>LV Line2.3</td>\n",
       "      <td>15-AL1/3-ST1A 0.4</td>\n",
       "      <td>52</td>\n",
       "      <td>53</td>\n",
       "      <td>0.12</td>\n",
       "      <td>1.8769</td>\n",
       "      <td>0.35</td>\n",
       "      <td>11.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.105</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>ol</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>LV Line2.4</td>\n",
       "      <td>15-AL1/3-ST1A 0.4</td>\n",
       "      <td>53</td>\n",
       "      <td>54</td>\n",
       "      <td>0.12</td>\n",
       "      <td>1.8769</td>\n",
       "      <td>0.35</td>\n",
       "      <td>11.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.105</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>ol</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>LV Line2.2.1</td>\n",
       "      <td>15-AL1/3-ST1A 0.4</td>\n",
       "      <td>52</td>\n",
       "      <td>55</td>\n",
       "      <td>0.12</td>\n",
       "      <td>1.8769</td>\n",
       "      <td>0.35</td>\n",
       "      <td>11.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.105</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>ol</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>LV Line2.2.2</td>\n",
       "      <td>15-AL1/3-ST1A 0.4</td>\n",
       "      <td>55</td>\n",
       "      <td>56</td>\n",
       "      <td>0.12</td>\n",
       "      <td>1.8769</td>\n",
       "      <td>0.35</td>\n",
       "      <td>11.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.105</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>ol</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            name           std_type  from_bus  to_bus  length_km  \\\n",
       "14    LV Line1.1      NAYY 4x120 SE        45      46       0.08   \n",
       "15    LV Line1.2      NAYY 4x120 SE        46      47       0.08   \n",
       "16    LV Line1.3      NAYY 4x120 SE        47      48       0.08   \n",
       "17    LV Line1.4      NAYY 4x120 SE        48      49       0.08   \n",
       "18    LV Line1.6      NAYY 4x120 SE        49      50       0.08   \n",
       "19    LV Line2.1      NAYY 4x120 SE        45      51       0.12   \n",
       "20    LV Line2.2      NAYY 4x120 SE        51      52       0.12   \n",
       "21    LV Line2.3  15-AL1/3-ST1A 0.4        52      53       0.12   \n",
       "22    LV Line2.4  15-AL1/3-ST1A 0.4        53      54       0.12   \n",
       "23  LV Line2.2.1  15-AL1/3-ST1A 0.4        52      55       0.12   \n",
       "24  LV Line2.2.2  15-AL1/3-ST1A 0.4        55      56       0.12   \n",
       "\n",
       "    r_ohm_per_km  x_ohm_per_km  c_nf_per_km  g_us_per_km  max_i_ka   df  \\\n",
       "14        0.2250          0.08        264.0          0.0     0.242  1.0   \n",
       "15        0.2250          0.08        264.0          0.0     0.242  1.0   \n",
       "16        0.2250          0.08        264.0          0.0     0.242  1.0   \n",
       "17        0.2250          0.08        264.0          0.0     0.242  1.0   \n",
       "18        0.2250          0.08        264.0          0.0     0.242  1.0   \n",
       "19        0.2250          0.08        264.0          0.0     0.242  1.0   \n",
       "20        0.2250          0.08        264.0          0.0     0.242  1.0   \n",
       "21        1.8769          0.35         11.0          0.0     0.105  1.0   \n",
       "22        1.8769          0.35         11.0          0.0     0.105  1.0   \n",
       "23        1.8769          0.35         11.0          0.0     0.105  1.0   \n",
       "24        1.8769          0.35         11.0          0.0     0.105  1.0   \n",
       "\n",
       "    parallel type  in_service  \n",
       "14         1   cs        True  \n",
       "15         1   cs        True  \n",
       "16         1   cs        True  \n",
       "17         1   cs        True  \n",
       "18         1   cs        True  \n",
       "19         1   cs        True  \n",
       "20         1   cs        True  \n",
       "21         1   ol        True  \n",
       "22         1   ol        True  \n",
       "23         1   ol        True  \n",
       "24         1   ol        True  "
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# create lines\n",
    "lv_lines = pd.read_csv('example_advanced/lv_lines.csv', sep=';', header=0, decimal=',')\n",
    "for _, lv_line in lv_lines.iterrows():\n",
    "    from_bus = pp.get_element_index(net, \"bus\", lv_line.from_bus)\n",
    "    to_bus = pp.get_element_index(net, \"bus\", lv_line.to_bus)\n",
    "    pp.create_line(net, from_bus, to_bus, length_km=lv_line.length, std_type=lv_line.std_type, name=lv_line.line_name)\n",
    "\n",
    "# show only low voltage lines\n",
    "net.line[net.line.from_bus.isin(lv_buses.index)]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Transformer\n",
    "\n",
    "<img src=\"pics/example_network_trafos_lv.png\" width=\"50%\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>std_type</th>\n",
       "      <th>hv_bus</th>\n",
       "      <th>lv_bus</th>\n",
       "      <th>sn_mva</th>\n",
       "      <th>vn_hv_kv</th>\n",
       "      <th>vn_lv_kv</th>\n",
       "      <th>vk_percent</th>\n",
       "      <th>vkr_percent</th>\n",
       "      <th>pfe_kw</th>\n",
       "      <th>...</th>\n",
       "      <th>tap_neutral</th>\n",
       "      <th>tap_min</th>\n",
       "      <th>tap_max</th>\n",
       "      <th>tap_step_percent</th>\n",
       "      <th>tap_step_degree</th>\n",
       "      <th>tap_pos</th>\n",
       "      <th>tap_phase_shifter</th>\n",
       "      <th>parallel</th>\n",
       "      <th>df</th>\n",
       "      <th>in_service</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>MV-LV-Trafo</td>\n",
       "      <td>None</td>\n",
       "      <td>41</td>\n",
       "      <td>45</td>\n",
       "      <td>0.4</td>\n",
       "      <td>10.0</td>\n",
       "      <td>0.4</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1.325</td>\n",
       "      <td>0.95</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>-2.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>2.5</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>False</td>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1 rows × 23 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          name std_type  hv_bus  lv_bus  sn_mva  vn_hv_kv  vn_lv_kv  \\\n",
       "1  MV-LV-Trafo     None      41      45     0.4      10.0       0.4   \n",
       "\n",
       "   vk_percent  vkr_percent  pfe_kw     ...      tap_neutral  tap_min tap_max  \\\n",
       "1         4.0        1.325    0.95     ...              0.0     -2.0     2.0   \n",
       "\n",
       "   tap_step_percent  tap_step_degree  tap_pos  tap_phase_shifter  parallel  \\\n",
       "1               2.5              NaN      0.0              False         1   \n",
       "\n",
       "    df  in_service  \n",
       "1  1.0        True  \n",
       "\n",
       "[1 rows x 23 columns]"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hv_bus = pp.get_element_index(net, \"bus\", \"Bus MV4\")\n",
    "lv_bus = pp.get_element_index(net, \"bus\",\"Bus LV0\")\n",
    "pp.create_transformer_from_parameters(net, hv_bus, lv_bus, sn_mva=.4, vn_hv_kv=10, vn_lv_kv=0.4, vkr_percent=1.325, vk_percent=4, pfe_kw=0.95, i0_percent=0.2375, tap_side=\"hv\", tap_neutral=0, tap_min=-2, tap_max=2, tap_step_percent=2.5, tp_pos=0, shift_degree=150, name='MV-LV-Trafo')\n",
    "\n",
    "#show only low voltage transformer\n",
    "net.trafo[net.trafo.lv_bus.isin(lv_buses.index)]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Switches"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>bus</th>\n",
       "      <th>element</th>\n",
       "      <th>et</th>\n",
       "      <th>type</th>\n",
       "      <th>closed</th>\n",
       "      <th>name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>45</td>\n",
       "      <td>14</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus LV0 - LV Line1.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>46</td>\n",
       "      <td>14</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus LV1.1 - LV Line1.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>46</td>\n",
       "      <td>15</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus LV1.1 - LV Line1.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>67</th>\n",
       "      <td>47</td>\n",
       "      <td>15</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus LV1.2 - LV Line1.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>68</th>\n",
       "      <td>47</td>\n",
       "      <td>16</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus LV1.2 - LV Line1.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>69</th>\n",
       "      <td>48</td>\n",
       "      <td>16</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus LV1.3 - LV Line1.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>48</td>\n",
       "      <td>17</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus LV1.3 - LV Line1.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>49</td>\n",
       "      <td>17</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus LV1.4 - LV Line1.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <td>49</td>\n",
       "      <td>18</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus LV1.4 - LV Line1.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>73</th>\n",
       "      <td>50</td>\n",
       "      <td>18</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus LV1.5 - LV Line1.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>74</th>\n",
       "      <td>45</td>\n",
       "      <td>19</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus LV0 - LV Line2.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75</th>\n",
       "      <td>51</td>\n",
       "      <td>19</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus LV2.1 - LV Line2.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>51</td>\n",
       "      <td>20</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus LV2.1 - LV Line2.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77</th>\n",
       "      <td>52</td>\n",
       "      <td>20</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus LV2.2 - LV Line2.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>52</td>\n",
       "      <td>21</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus LV2.2 - LV Line2.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>53</td>\n",
       "      <td>21</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus LV2.3 - LV Line2.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>53</td>\n",
       "      <td>22</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus LV2.3 - LV Line2.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>81</th>\n",
       "      <td>54</td>\n",
       "      <td>22</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus LV2.4 - LV Line2.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <td>52</td>\n",
       "      <td>23</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus LV2.2 - LV Line2.2.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>55</td>\n",
       "      <td>23</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus LV2.2.1 - LV Line2.2.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>84</th>\n",
       "      <td>55</td>\n",
       "      <td>24</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus LV2.2.1 - LV Line2.2.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>85</th>\n",
       "      <td>56</td>\n",
       "      <td>24</td>\n",
       "      <td>l</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch Bus LV2.2.2 - LV Line2.2.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>87</th>\n",
       "      <td>45</td>\n",
       "      <td>1</td>\n",
       "      <td>t</td>\n",
       "      <td>LBS</td>\n",
       "      <td>True</td>\n",
       "      <td>Switch LV0 - MV-LV-Trafo</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    bus  element et type  closed                               name\n",
       "64   45       14  l  LBS    True        Switch Bus LV0 - LV Line1.1\n",
       "65   46       14  l  LBS    True      Switch Bus LV1.1 - LV Line1.1\n",
       "66   46       15  l  LBS    True      Switch Bus LV1.1 - LV Line1.2\n",
       "67   47       15  l  LBS    True      Switch Bus LV1.2 - LV Line1.2\n",
       "68   47       16  l  LBS    True      Switch Bus LV1.2 - LV Line1.3\n",
       "69   48       16  l  LBS    True      Switch Bus LV1.3 - LV Line1.3\n",
       "70   48       17  l  LBS    True      Switch Bus LV1.3 - LV Line1.4\n",
       "71   49       17  l  LBS    True      Switch Bus LV1.4 - LV Line1.4\n",
       "72   49       18  l  LBS    True      Switch Bus LV1.4 - LV Line1.6\n",
       "73   50       18  l  LBS    True      Switch Bus LV1.5 - LV Line1.6\n",
       "74   45       19  l  LBS    True        Switch Bus LV0 - LV Line2.1\n",
       "75   51       19  l  LBS    True      Switch Bus LV2.1 - LV Line2.1\n",
       "76   51       20  l  LBS    True      Switch Bus LV2.1 - LV Line2.2\n",
       "77   52       20  l  LBS    True      Switch Bus LV2.2 - LV Line2.2\n",
       "78   52       21  l  LBS    True      Switch Bus LV2.2 - LV Line2.3\n",
       "79   53       21  l  LBS    True      Switch Bus LV2.3 - LV Line2.3\n",
       "80   53       22  l  LBS    True      Switch Bus LV2.3 - LV Line2.4\n",
       "81   54       22  l  LBS    True      Switch Bus LV2.4 - LV Line2.4\n",
       "82   52       23  l  LBS    True    Switch Bus LV2.2 - LV Line2.2.1\n",
       "83   55       23  l  LBS    True  Switch Bus LV2.2.1 - LV Line2.2.1\n",
       "84   55       24  l  LBS    True  Switch Bus LV2.2.1 - LV Line2.2.2\n",
       "85   56       24  l  LBS    True  Switch Bus LV2.2.2 - LV Line2.2.2\n",
       "87   45        1  t  LBS    True           Switch LV0 - MV-LV-Trafo"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lv_buses\n",
    "# Bus-line switches\n",
    "lv_ls = net.line[(net.line.from_bus.isin(lv_buses.index)) & (net.line.to_bus.isin(lv_buses.index))]\n",
    "for _, line in lv_ls.iterrows():\n",
    "        pp.create_switch(net, line.from_bus, line.name, et='l', closed=True, type='LBS', name='Switch %s - %s' % (net.bus.name.at[line.from_bus], line['name']))\n",
    "        pp.create_switch(net, line.to_bus, line.name, et='l', closed=True, type='LBS', name='Switch %s - %s' % (net.bus.name.at[line.to_bus], line['name']))\n",
    "\n",
    "# Trafo-line switches\n",
    "pp.create_switch(net, pp.get_element_index(net, \"bus\", 'Bus MV4'), pp.get_element_index(net, \"trafo\", 'MV-LV-Trafo'), et='t', closed=True, type='LBS', name='Switch MV4 - MV-LV-Trafo')\n",
    "pp.create_switch(net, pp.get_element_index(net, \"bus\", 'Bus LV0'), pp.get_element_index(net, \"trafo\", 'MV-LV-Trafo'), et='t', closed=True, type='LBS', name='Switch LV0 - MV-LV-Trafo')\n",
    "\n",
    "# show only low vvoltage switches\n",
    "net.switch[net.switch.bus.isin(lv_buses.index)]\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Loads\n",
    "\n",
    "<img src=\"pics/example_network_loads_lv.png\" width=\"50%\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>bus</th>\n",
       "      <th>p_mw</th>\n",
       "      <th>q_mvar</th>\n",
       "      <th>const_z_percent</th>\n",
       "      <th>const_i_percent</th>\n",
       "      <th>sn_mva</th>\n",
       "      <th>scaling</th>\n",
       "      <th>in_service</th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>Further LV-Feeders Load</td>\n",
       "      <td>45</td>\n",
       "      <td>0.10</td>\n",
       "      <td>0.10</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>Residential Load</td>\n",
       "      <td>46</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>Residential Load(1)</td>\n",
       "      <td>47</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>Residential Load(2)</td>\n",
       "      <td>48</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>Residential Load(3)</td>\n",
       "      <td>49</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>Residential Load(4)</td>\n",
       "      <td>50</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>Rural Load</td>\n",
       "      <td>51</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>Rural Load(1)</td>\n",
       "      <td>52</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>Rural Load(2)</td>\n",
       "      <td>53</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>Rural Load(3)</td>\n",
       "      <td>54</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>Rural Load(4)</td>\n",
       "      <td>55</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>Rural Load(5)</td>\n",
       "      <td>56</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                       name  bus  p_mw  q_mvar  const_z_percent  \\\n",
       "13  Further LV-Feeders Load   45  0.10    0.10              0.0   \n",
       "14         Residential Load   46  0.01    0.03              0.0   \n",
       "15      Residential Load(1)   47  0.01    0.03              0.0   \n",
       "16      Residential Load(2)   48  0.01    0.03              0.0   \n",
       "17      Residential Load(3)   49  0.01    0.03              0.0   \n",
       "18      Residential Load(4)   50  0.01    0.03              0.0   \n",
       "19               Rural Load   51  0.01    0.03              0.0   \n",
       "20            Rural Load(1)   52  0.01    0.03              0.0   \n",
       "21            Rural Load(2)   53  0.01    0.03              0.0   \n",
       "22            Rural Load(3)   54  0.01    0.03              0.0   \n",
       "23            Rural Load(4)   55  0.01    0.03              0.0   \n",
       "24            Rural Load(5)   56  0.01    0.03              0.0   \n",
       "\n",
       "    const_i_percent  sn_mva  scaling  in_service  type  \n",
       "13              0.0     NaN      1.0        True  None  \n",
       "14              0.0     NaN      1.0        True  None  \n",
       "15              0.0     NaN      1.0        True  None  \n",
       "16              0.0     NaN      1.0        True  None  \n",
       "17              0.0     NaN      1.0        True  None  \n",
       "18              0.0     NaN      1.0        True  None  \n",
       "19              0.0     NaN      1.0        True  None  \n",
       "20              0.0     NaN      1.0        True  None  \n",
       "21              0.0     NaN      1.0        True  None  \n",
       "22              0.0     NaN      1.0        True  None  \n",
       "23              0.0     NaN      1.0        True  None  \n",
       "24              0.0     NaN      1.0        True  None  "
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lv_loads = pd.read_csv('example_advanced/lv_loads.csv', sep=';', header=0, decimal=',')\n",
    "for _, load in lv_loads.iterrows():\n",
    "    bus_idx = pp.get_element_index(net, \"bus\", load.bus)\n",
    "    pp.create_load(net, bus_idx, p_mw=load.p, q_mvar=load.q, name=load.load_name)\n",
    "    \n",
    "# show only low voltage loads\n",
    "net.load[net.load.bus.isin(lv_buses.index)]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Static generators\n",
    "\n",
    "<img src=\"pics/example_network_sgens_lv.png\"  width=\"50%\">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>bus</th>\n",
       "      <th>p_mw</th>\n",
       "      <th>q_mvar</th>\n",
       "      <th>sn_mva</th>\n",
       "      <th>scaling</th>\n",
       "      <th>in_service</th>\n",
       "      <th>type</th>\n",
       "      <th>current_source</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>PV</td>\n",
       "      <td>46</td>\n",
       "      <td>0.06</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.012</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>PV</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>PV(1)</td>\n",
       "      <td>48</td>\n",
       "      <td>0.05</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.010</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>PV</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>PV(2)</td>\n",
       "      <td>53</td>\n",
       "      <td>0.05</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.010</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>PV</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>PV(3)</td>\n",
       "      <td>54</td>\n",
       "      <td>0.05</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.010</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>PV</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>PV(4)</td>\n",
       "      <td>55</td>\n",
       "      <td>0.05</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.010</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>PV</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>PV(5)</td>\n",
       "      <td>56</td>\n",
       "      <td>0.05</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.010</td>\n",
       "      <td>1.0</td>\n",
       "      <td>True</td>\n",
       "      <td>PV</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     name  bus  p_mw  q_mvar  sn_mva  scaling  in_service type  current_source\n",
       "5      PV   46  0.06     0.0   0.012      1.0        True   PV            True\n",
       "6   PV(1)   48  0.05     0.0   0.010      1.0        True   PV            True\n",
       "7   PV(2)   53  0.05     0.0   0.010      1.0        True   PV            True\n",
       "8   PV(3)   54  0.05     0.0   0.010      1.0        True   PV            True\n",
       "9   PV(4)   55  0.05     0.0   0.010      1.0        True   PV            True\n",
       "10  PV(5)   56  0.05     0.0   0.010      1.0        True   PV            True"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lv_sgens = pd.read_csv('example_advanced/lv_sgens.csv', sep=';', header=0, decimal=',')\n",
    "for _, sgen in lv_sgens.iterrows():\n",
    "    bus_idx = pp.get_element_index(net, \"bus\", sgen.bus)\n",
    "    pp.create_sgen(net, bus_idx, p_mw=sgen.p, q_mvar=sgen.q, sn_mva=sgen.sn, type=sgen.type, name=sgen.sgen_name)\n",
    "\n",
    "# show only low voltage static generators\n",
    "net.sgen[net.sgen.bus.isin(lv_buses.index)]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Run a Power Flow"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "This pandapower network includes the following parameter tables:\n",
       "   - bus (57 elements)\n",
       "   - load (25 elements)\n",
       "   - sgen (11 elements)\n",
       "   - gen (1 element)\n",
       "   - switch (88 elements)\n",
       "   - shunt (1 element)\n",
       "   - ext_grid (1 element)\n",
       "   - line (25 elements)\n",
       "   - trafo (2 elements)\n",
       "   - trafo3w (1 element)\n",
       "   - impedance (1 element)\n",
       "   - xward (2 elements)\n",
       " and the following results tables:\n",
       "   - res_bus (57 elements)\n",
       "   - res_line (25 elements)\n",
       "   - res_trafo (2 elements)\n",
       "   - res_trafo3w (1 element)\n",
       "   - res_impedance (1 element)\n",
       "   - res_ext_grid (1 element)\n",
       "   - res_load (25 elements)\n",
       "   - res_sgen (11 elements)\n",
       "   - res_shunt (1 element)\n",
       "   - res_gen (1 element)\n",
       "   - res_xward (2 elements)"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pp.runpp(net, calculate_voltage_angles=True, init=\"dc\")\n",
    "net"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
